import request from "@/utils/request";
import type {
  GetSpuListParams,
  GetSpuListResponse,
  GetSaleAttrList,
  AddOrUpdateSpu,
  SpuImageList,
  SpuSaleAttrList,
} from "./model/spuModel";
enum Api {
  getSpuPageUrl = `/admin/product`,
  GetSaleAttrListUrl = `/admin/product/baseSaleAttrList`,
  getAddAttrUrl = `/admin/product/saveSpuInfo`,
  getSpuImgListUrl = `/admin/product/spuImageList`,
  getSpuSaleAttrListUrl = `/admin/product/spuSaleAttrList`,
  getUpdateSpuInfoUrl = `/admin/product/updateSpuInfo`,
}
export const getSpuPageApi = ({
  page,
  limit,
  category3Id,
}: GetSpuListParams) => {
  return request.get<any, GetSpuListResponse>(
    Api.getSpuPageUrl + `/${page}/${limit}`,
    {
      params: {
        category3Id,
      },
    }
  );
};
// 基础销售属性的接口
export const GetSaleAttrListApi = () => {
  return request.get<any, GetSaleAttrList>(Api.GetSaleAttrListUrl);
};
// 新增spu
export const getAddAttrApi = (data: AddOrUpdateSpu) => {
  return request.post<any, null>(Api.getAddAttrUrl, data);
};
// 更新spu
export const getUpdateSpuInfoApi = (data: AddOrUpdateSpu) => {
  return request.post<any, null>(Api.getUpdateSpuInfoUrl, data);
};
// 获取图片列表
export const getSpuImgListApi = (spuId: number) => {
  return request.get<any, SpuImageList>(Api.getSpuImgListUrl + `/${spuId}`);
};
// 获取属性值列表
export const getSpuSaleAttrListApi = (spuId: number) => {
  return request.get<any, SpuSaleAttrList>(
    Api.getSpuSaleAttrListUrl + `/${spuId}`
  );
};
